<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
		<meta charset="utf-8">
		<title>淘天机站群系统管理后台</title>
		<!-- include header_meta -->
</head>
<body>
	<!-- include header -->
	<div class="cp-wrap {if $jnarrow}jnarrow{/if}">
		<div class="crumb"></div>
		
		<!--其他操作-->
		<div class="cp-table-top">
			<input type="submit" class="btn" value="添加采集规则" onclick="window.location.href='?m=catch&a=add&yuming_id={$currentYumingId}' ">
		</div>
		<div class="cp-table">
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
				<tbody>
					<tr>
						<th width="50" align="left">ID</th>
						<th align="left">采集规则列表</th>
						<th align="left">采集站点</th>
						<th width="300" align="center">操作</th>
					</tr>
					<!-- foreach $list -->
					<tr>
						<td align="left">{$id}</td>
						<td align="left">{$listurl}</td>
						<td align="left">{if $yuming_id==$currentYuming[id]}当前站点 {elseif  $yuming_id==0}所有站点随机{/if}</td>
						<td align="center">
							<a href="javascript:void(0)" onclick="window.open('?m=catchtest&yuming_id={$currentYumingId}&id={$id}','','height=500, width=900, top=200, left=300')" target="_blank">测试</a>
							<a href="?m=catch&a=edit&id={$id}&yuming_id={$currentYumingId}">修改</a>
							<a href="?m=catch&a=del&id={$id}&yuming_id={$currentYumingId}" onclick="return confirm('确定删除吗?')">删除</a>
						</td>
					</tr>
					<!-- /foreach -->
				</tbody>
			</table>
		</div>
		<!-- if empty($list) -->
		<div class="noresult">暂时没有可显示数据</div>
		<!-- /if -->
		<div class="cl" style="padding:10px;">
			<input type="submit" class="btn fl" value="手工采集" onclick="start_caiji()"  style="float:left;"/>
			<div class="btn2" style="float:left;">自动采集开关</div>
			<div class="cj" id="{$auto}" rel="{$currentYumingId}" style="float:left;"></div>
		</div>
		<div class="cp-pages">
			{$page}
		</div>
	</div>
	<!-- include footer -->
	<div id="poplayer" style="background: #272822;">
		<div style="height: 320px; color: #ccc; overflow-y: scroll;" id="cj_txt">

		</div>
		<div style="text-align: center;">
			<input type="submit" class="btn" value="停止（关闭）" onclick="close_caiji()" />
		</div>
	</div>

	<script>
		function changeCaiji(yuming_id,obj){
			var tt = $(obj).attr("data");
			if(tt==1){
				$(obj).removeClass("turnbg_1");
				$(obj).addClass("turnbg_0");
				$(obj).attr("data",0);
			}else{
				$(obj).removeClass("turnbg_0");
				$(obj).addClass("turnbg_1");
				$(obj).attr("data",1);
			}
			var ts = $(obj).attr("data");
			$.ajax({
				'url':"?m=catch&a=switchcaiji",
				'type': 'post',
				'dataType': 'json',
				'data': {'yuming_id':yuming_id,'data':ts},
				success:function(data){
					if (data.status!=1) {
						$(obj).removeClass("turnbg_1");
						$(obj).addClass("turnbg_0");
						$(obj).attr("data",0);
					}
					cpAlert(data.msg);
				}
			})
		}
		function NoCheck(){
			if(confirm("您还没有授权站点，马上授权绑定！")){
				window.location.href="?m=system&a=bind";
			}
		}

		var yuming_id=$(".cj").attr("rel");
		if(yuming_id==""){
			$('.btn2').hide();
			$('.cj').hide();
		}
		var cj_auto = false;
		var currentAjax = [];
		function start_auto(){
			if(cj_auto==true){
				document.getElementById('cj_txt').scrollTop = document.getElementById('cj_txt').scrollHeight;
				currentAjax = $.ajax({
					type: "GET",
					url: "/catch/caijiArticle?yumingid={$currentYumingId}",
					success: function(d){
						if(d.length>0){
							$("#cj_txt").append(d+"<br/>");
						}
						if(d.indexOf("Error:")==-1){
							setTimeout(function(){
								start_auto();
							}, 200);
						}
					},
					error: function(d){
						if(d.responseText.length>0){
							$("#cj_txt").append(d.responseText+"<br/>");
						}
						if(d.responseText.indexOf("Error:")==-1){
							setTimeout(function(){
								start_auto();
							}, 500);
						}
					}
				})
			}
		}

		function start_caiji(){
			cj_auto = true;
			$("#cj_txt").html("开始采集<br>");
			$("#poplayer").show();
			start_auto();
		}
		function close_caiji(){
			cj_auto = false;
			$("#poplayer").hide();
			currentAjax.abort();
		}

		$.ajax({
			'url':"?m=catch&a=getCaiji",
			'type': 'post',
			'dataType': 'json',
			success:function(data){
				var ac=$(".cj").attr("id");
				var yuming_id=$(".cj").attr("rel");
				if(data.status==1){
					var str = "<div class='switch turnbg_"+ac+"' data='"+ac+"' onclick='changeCaiji("+yuming_id+",this)'></div>";
					$(".cj").html(str);
				}else{
					var str = "<div class='switch turnbg_0'  onclick='NoCheck()'></div>";
					$(".cj").html(str);
				}
			},
			error: function(){ }
		});
	</script>
</body>
</html>